import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/ui/draw_under_line.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

/// 满减活动
class FullReduceActivity extends StatefulWidget {
  final bool isAll;

  const FullReduceActivity({Key? key, this.isAll = true}) : super(key: key);

  @override
  State<FullReduceActivity> createState() => _FullReduceActivityState();
}

class _FullReduceActivityState extends State<FullReduceActivity> {
  TextStyle get defaultStyle {
    return StylesUtils.customTextStyle(
        color: ColorsUtils.colorCc0, fontSize: Sizes.default13, lineHeight: 1.5);
  }

  TextStyle get style {
    return StylesUtils.customTextStyle(color: ColorsUtils.colorFb8, fontSize: Sizes.default15);
  }

  TextStyle get redStyle {
    return StylesUtils.customTextStyle(
        color: ColorsUtils.colorFb8, fontSize: Sizes.default13, lineHeight: 1.5);
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          Container(
            margin: const EdgeInsets.all(Sizes.default20),
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default10)),
            child: ListBody(
              children: [
                DrawUnderLine(
                  color: ColorsUtils.parseColorFromHexString('#D7D7D7'),
                  child: Container(
                    padding: const EdgeInsets.only(
                        bottom: Sizes.default20,
                        top: Sizes.default10,
                        left: Sizes.default15,
                        right: Sizes.default15),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                          flex: 1,
                          child: Container(
                            alignment: Alignment.topLeft,
                            child: Text(
                              'No.111',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color797),
                            ),
                          ),
                        ),
                        Expanded(
                          flex: 5,
                          child: Container(
                            padding: const EdgeInsets.only(left: Sizes.default10),
                            child: Column(
                              children: [
                                Container(
                                  alignment: Alignment.topLeft,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    children: [
                                      Text(
                                        '满减活动',
                                        style: StylesUtils.customTextStyle(
                                            fontSize: Sizes.default16, color: ColorsUtils.colorFf6),
                                      ),
                                      Container(
                                        constraints: const BoxConstraints.expand(
                                            width: Sizes.default70, height: Sizes.default20),
                                        alignment: Alignment.center,
                                        decoration: BoxDecoration(
                                            color: ColorsUtils.rgba(251, 137, 116, 1),
                                            borderRadius: BorderRadius.circular(Sizes.default10)),
                                        child: Text.rich(TextSpan(children: [
                                          WidgetSpan(
                                              child: ToolsUtils.getUrlSvg(
                                                  'https://cdn7.axureshop.com/demo/1525603/images/团购管理/u3043.svg',
                                                  width: Sizes.default13,
                                                  height: Sizes.default13),
                                              alignment: PlaceholderAlignment.middle),
                                          TextSpan(
                                              text: '审核中',
                                              style: StylesUtils.customTextStyle(
                                                  fontSize: Sizes.default12))
                                        ])),
                                      )
                                    ],
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                  child: Text(
                                    '满500P减50P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  child: Text(
                                    '满300P减30P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                  child: Text(
                                    '满100P减10P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  child: Text(
                                    '剩余库存：300 件',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '活动日期：2021-12-01 至 2021-12-31',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '使用方式：移动端',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '其他说明：店铺所有用户可用',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '修改时间：2021-11-01 10:09:37',
                                    style: redStyle,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                ),
                SizedBox(
                  height: Sizes.default60,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Expanded(
                          child: Center(
                        child: TextButton(onPressed: () {}, child: Text('', style: style)),
                      )),
                      Expanded(
                          child: Center(
                        child: TextButton(
                            onPressed: () {
                              Get.toNamed(RouteGet.marketReduceEdit);
                            },
                            child: Text('编辑活动', style: style)),
                      ))
                    ],
                  ),
                )
              ],
            ),
          ),
          Container(
            margin: const EdgeInsets.all(Sizes.default20),
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default10)),
            child: ListBody(
              children: [
                DrawUnderLine(
                  color: ColorsUtils.parseColorFromHexString('#D7D7D7'),
                  child: Container(
                    padding: const EdgeInsets.only(
                        bottom: Sizes.default20,
                        top: Sizes.default10,
                        left: Sizes.default15,
                        right: Sizes.default15),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                          flex: 1,
                          child: Container(
                            alignment: Alignment.topLeft,
                            child: Text(
                              'No.110',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color797),
                            ),
                          ),
                        ),
                        Expanded(
                          flex: 5,
                          child: Container(
                            padding: const EdgeInsets.only(left: Sizes.default10),
                            child: Column(
                              children: [
                                Container(
                                  alignment: Alignment.topLeft,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    children: [
                                      Text(
                                        '满减活动',
                                        style: StylesUtils.customTextStyle(
                                            fontSize: Sizes.default16, color: ColorsUtils.colorFf6),
                                      ),
                                      Container(
                                        constraints: const BoxConstraints.expand(
                                            width: Sizes.default70, height: Sizes.default20),
                                        alignment: Alignment.center,
                                        decoration: BoxDecoration(
                                            color: ColorsUtils.rgba(82, 190, 237, 1),
                                            borderRadius: BorderRadius.circular(Sizes.default10)),
                                        child: Text.rich(TextSpan(children: [
                                          WidgetSpan(
                                              child: ToolsUtils.getUrlSvg(
                                                  'https://cdn7.axureshop.com/demo/1525603/images/团购管理/u2984.svg',
                                                  width: Sizes.default13,
                                                  height: Sizes.default13),
                                              alignment: PlaceholderAlignment.middle),
                                          TextSpan(
                                              text: '未开始',
                                              style: StylesUtils.customTextStyle(
                                                  fontSize: Sizes.default12))
                                        ])),
                                      )
                                    ],
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                  child: Text(
                                    '满500P减50P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  child: Text(
                                    '满300P减30P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                  child: Text(
                                    '满100P减10P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '活动日期：2021-12-01 至 2021-12-31',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '使用方式：移动端',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '其他说明：店铺所有用户可用',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '创建时间：2021-11-30 10:09:37',
                                    style: redStyle,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                ),
                SizedBox(
                  height: Sizes.default60,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Expanded(
                          child: Center(
                        child: TextButton(
                            onPressed: () {
                              pauseActivity();
                            },
                            child: Text('暂停优惠', style: style)),
                      )),
                      Expanded(
                          child: Center(
                        child: TextButton(
                            onPressed: () {
                              Get.toNamed(RouteGet.marketReduceInfo);
                            },
                            child: Text('使用详情', style: style)),
                      ))
                    ],
                  ),
                )
              ],
            ),
          ),
          Container(
            margin: const EdgeInsets.all(Sizes.default20),
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default10)),
            child: ListBody(
              children: [
                DrawUnderLine(
                  color: ColorsUtils.parseColorFromHexString('#D7D7D7'),
                  child: Container(
                    padding: const EdgeInsets.only(
                        bottom: Sizes.default20,
                        top: Sizes.default10,
                        left: Sizes.default15,
                        right: Sizes.default15),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                          flex: 1,
                          child: Container(
                            alignment: Alignment.topLeft,
                            child: Text(
                              'No.109',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color797),
                            ),
                          ),
                        ),
                        Expanded(
                          flex: 5,
                          child: Container(
                            padding: const EdgeInsets.only(left: Sizes.default10),
                            child: Column(
                              children: [
                                Container(
                                  alignment: Alignment.topLeft,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    children: [
                                      Text(
                                        '满减活动',
                                        style: StylesUtils.customTextStyle(
                                            fontSize: Sizes.default16, color: ColorsUtils.colorFf6),
                                      ),
                                      Container(
                                        constraints: const BoxConstraints.expand(
                                            width: Sizes.default70, height: Sizes.default20),
                                        alignment: Alignment.center,
                                        decoration: BoxDecoration(
                                            color: ColorsUtils.rgba(204, 204, 204, 1),
                                            borderRadius: BorderRadius.circular(Sizes.default10)),
                                        child: Text.rich(TextSpan(children: [
                                          WidgetSpan(
                                              child: ToolsUtils.getUrlSvg(
                                                  'https://cdn7.axureshop.com/demo/1525603/images/团购管理/u2984.svg',
                                                  width: Sizes.default13,
                                                  height: Sizes.default13),
                                              alignment: PlaceholderAlignment.middle),
                                          TextSpan(
                                              text: '已结束',
                                              style: StylesUtils.customTextStyle(
                                                  fontSize: Sizes.default12))
                                        ])),
                                      )
                                    ],
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                  child: Text(
                                    '满500P减50P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  child: Text(
                                    '满200P减25P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                  child: Text(
                                    '满1000P减150P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '活动日期：2021-12-01 至 2021-12-31',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '使用方式：移动端',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '其他说明：店铺所有用户可用',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '创建时间：2021-11-30 10:09:37',
                                    style: redStyle,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                ),
                SizedBox(
                  height: Sizes.default60,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Expanded(
                          child: Center(
                        child: TextButton(onPressed: () {}, child: Text('', style: style)),
                      )),
                      Expanded(
                          child: Center(
                        child: TextButton(
                            onPressed: () {
                              Get.toNamed(RouteGet.marketReduceInfo);
                            },
                            child: Text('使用详情', style: style)),
                      ))
                    ],
                  ),
                )
              ],
            ),
          ),
          Container(
            margin: const EdgeInsets.all(Sizes.default20),
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default10)),
            child: ListBody(
              children: [
                DrawUnderLine(
                  color: ColorsUtils.parseColorFromHexString('#D7D7D7'),
                  child: Container(
                    padding: const EdgeInsets.only(
                        bottom: Sizes.default20,
                        top: Sizes.default10,
                        left: Sizes.default15,
                        right: Sizes.default15),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                          flex: 1,
                          child: Container(
                            alignment: Alignment.topLeft,
                            child: Text(
                              'No.108',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color797),
                            ),
                          ),
                        ),
                        Expanded(
                          flex: 5,
                          child: Container(
                            padding: const EdgeInsets.only(left: Sizes.default10),
                            child: Column(
                              children: [
                                Container(
                                  alignment: Alignment.topLeft,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    children: [
                                      Text(
                                        '满减活动',
                                        style: StylesUtils.customTextStyle(
                                            fontSize: Sizes.default16, color: ColorsUtils.colorFf6),
                                      ),
                                      Container(
                                        constraints: const BoxConstraints.expand(
                                            width: Sizes.default80, height: Sizes.default20),
                                        alignment: Alignment.center,
                                        decoration: BoxDecoration(
                                            color: ColorsUtils.rgba(255, 0, 0, 1),
                                            borderRadius: BorderRadius.circular(Sizes.default10)),
                                        child: Text.rich(TextSpan(children: [
                                          WidgetSpan(
                                              child: ToolsUtils.getUrlSvg(
                                                  'https://cdn7.axureshop.com/demo/1525603/images/团购管理/u3043.svg',
                                                  width: Sizes.default13,
                                                  height: Sizes.default13),
                                              alignment: PlaceholderAlignment.middle),
                                          TextSpan(
                                              text: '审核失败',
                                              style: StylesUtils.customTextStyle(
                                                  fontSize: Sizes.default12))
                                        ])),
                                      )
                                    ],
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                  child: Text(
                                    '满500P减50P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  child: Text(
                                    '满300P减30P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                  child: Text(
                                    '满100P减10P',
                                    style: defaultStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '活动日期：2021-12-01 至 2021-12-31',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '使用方式：移动端',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '其他说明：店铺所有用户可用',
                                    style: redStyle,
                                  ),
                                ),
                                Container(
                                  alignment: Alignment.topLeft,
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '创建时间：2021-11-30 10:09:37',
                                    style: redStyle,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                ),
                SizedBox(
                  height: Sizes.default60,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Expanded(
                          child: Center(
                        child: TextButton(onPressed: () {}, child: Text('', style: style)),
                      )),
                      Expanded(
                          child: Center(
                        child: TextButton(
                            onPressed: () {
                              Get.toNamed(RouteGet.marketReduceEdit);
                            },
                            child: Text('编辑活动', style: style)),
                      ))
                    ],
                  ),
                )
              ],
            ),
          ),
        ],
      ),
    );
  }

  void pauseActivity([String title = '是否暂停此活动?']) async {
    final dialog = BrnDialog(
        verticalDivider: const VerticalDivider(
          width: 1.0,
          color: Colors.black,
        ),
        divider: const Divider(
          height: 1.0,
          color: Colors.black,
        ),
        contentWidget: ListBody(
          children: [
            Container(
              padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
              alignment: Alignment.center,
              child: Text(
                title,
                style: StylesUtils.customTextStyle(
                    color: ColorsUtils.color000, fontSize: Sizes.default18),
              ),
            ),
          ],
        ),
        actionsWidget: [
          Container(
              alignment: Alignment.center,
              child: TextButton(
                onPressed: () {
                  Navigator.pop(context, 0);
                },
                child: Text(
                  '取消',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color333, fontSize: Sizes.default16),
                ),
              )),
          Container(
              alignment: Alignment.center,
              child: TextButton(
                onPressed: () {
                  Navigator.pop(context, 1);
                },
                child: Text('确定',
                    style: StylesUtils.customTextStyle(
                        fontSize: Sizes.default16, color: ColorsUtils.colorFf6)),
              ))
        ],
        themeData: BrnDialogConfig(
            dialogWidth: 280,
            radius: Sizes.default10,
            titlePaddingSm: EdgeInsets.zero,
            titlePaddingLg: EdgeInsets.zero,
            contentPaddingSm: EdgeInsets.zero,
            contentPaddingLg: EdgeInsets.zero,
            contentTextAlign: TextAlign.center));
    int? result = await showDialog<int>(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return dialog;
      },
    );
    if (result == 1) {
      /// 拨打电话
    }
  }
}
